package com.tepth.remote.control.service.job;

import android.support.annotation.NonNull;

import com.blankj.utilcode.util.ServiceUtils;
import com.evernote.android.job.Job;
import com.evernote.android.job.JobRequest;
import com.tepth.remote.control.service.ControlService;

import java.util.concurrent.TimeUnit;

/**
 * Description:
 *
 * @author Hequn.Lee
 * @date 2018/11/12
 */
public class ControlCheckJob extends Job {

    static final String TAG = "check_live_tag";
    public static final String CONTROL_SERVICE_NAME = "com.tepth.remote.control.service.ControlService";

    @NonNull
    @Override
    protected Result onRunJob(@NonNull Params params) {
        if (!ServiceUtils.isServiceRunning(CONTROL_SERVICE_NAME)) {
            ServiceUtils.startService(ControlService.class);
        }
        return Result.SUCCESS;
    }

    public static void scheduleJob() {
        new JobRequest.Builder(ControlCheckJob.TAG)
                .setPeriodic(TimeUnit.SECONDS.toMillis(900))
                .setUpdateCurrent(true)
                .build()
                .schedule();
    }
}
